import Mock from 'mockjs2';
import { builder, getDataByPagination } from '../util';

// 分页获取应用
const readApplications = (options) => {
  const { next, key, pageSize, pageNo, totalCount, totalPage } = getDataByPagination(options, 100);

  const mockData = Mock.mock({
    [`result|${next - 1}`]: [
      {
        'id|+1': key + 1,
        // 应用名称
        name: '@cword(2, 8)',
        desc: '@cword(0, 120)',
        logo: `@image('64x64', '#50B347', 'Logo')`,
        type: '@pick([1, 2, 3])',
        status: '@pick([0, 1])',
        updateTime: '@datetime'
      }
    ]
  });

  return builder({
    pageSize,
    pageNo,
    totalCount,
    totalPage,
    data: mockData.result
  }, '', 200);
}

// 创建应用
const createApplication = () => {
  return builder('', '', 200);
}

// 更新应用
const updateApplication = () => {
  return builder('', '', 200);
}

// 启用禁用应用
const enableApplication = () => {
  return builder('', '', 200);
}

Mock.mock(/\/applications/, 'get', readApplications);
Mock.mock(/\/application/, 'post', createApplication);
Mock.mock(/\/application/, 'put', updateApplication);
Mock.mock(/\/application/, 'post', enableApplication);
